n = input()
if len(n) ==4:
  n1 = n[0]
  n2 = n[1]
  n3 = n[2]
  n4 = n[3]
  spis = [int(n1),int(n2),int(n3),int(n4),int(n1+n2),int(n1+n2+n3),int(n1+n2+n3+n4),int(n2+n3),int(n2+n3+n4),int(n3+n4)]
  spis.sort()
  spis = spis[::-1]
  for x in spis:
    F = True
    for d in range(2, x//2+1):
      if x % d == 0:
        F = False
        break
    if F==True:
      print(x)
      break
  if F == False:
    print(0)
else:
   print('0')
